<?php

// Web Service for Lazy-K Gallery's cache manager

header('Pragma: no-cache');
header('Expires: 0');

require_once('../../../wp-blog-header.php');
require_once('./lazy-k-gallery-image.php');
require_once('./lazy-k-gallery-config.php');

// load default settings for any option that doesn't exist
lzk_setDefaultOptions();

// get the paths to the gallery
lzk_buildPaths();

$file = stripslashes($_REQUEST['file']); //v1.3.2

$resultText = 'Processed: '.$file.'<br/>';	
$success = true;

// make sure we can load the wordpress settings
if (get_option('siteurl') == '')
{
	$resultText .= 'Error: Could not load Wordpress settings<br/>';
	echo $resultText;
	return;
}

// delete thumbnail folder
if ($_REQUEST['deletethumbs'] == 'true')
{		
	$resultText .= 'Deleting thumbnail...';		
	if (lzk_deleteCacheFolder($file, true, $deleteResultText)) // v1.4
	{
		$resultText .= 'Success! - '.$deleteResultText.'<br/>';
	}
	else
	{
		$resultText .= '<strong>Failed!</strong> - '.$deleteResultText.'<br/>';
		$success = false;
	}		
}

// delete slide folder
if ($_REQUEST['deleteslides'] == 'true')
{
	$resultText .= 'Deleting slides...';

	if (lzk_deleteCacheFolder($file, false, $deleteResultText)) // v1.4
	{
		$resultText .= 'Success! - '.$deleteResultText.'<br/>';
	}
	else
	{
		$resultText .= '<strong>Failed!</strong> - '.$deleteResultText.'<br/>';
		$success = false;
	}			
}

// create cached thumbnail
if ($_REQUEST['createthumbs'] == 'true')
{
	$resultText .= 'Creating thumbnail.<br/>';

	//v1.3.3
	if (lzk_createCachedImage($file, true, $createResultText))
	{
		$resultText .= 'Success! - '.$createResultText.'<br/>';
	}
	else
	{
		$resultText .= '<strong>Failed!</strong> - '.$createResultText.'<br/>';
		$success = false;
	}
}

// create cached slide
if ($_REQUEST['createslides'] == 'true')
{
	$resultText .= 'Creating slides.<br/>';

	//v1.3.3
	if (lzk_createCachedImage($file, false, $createResultText))
	{
		$resultText .= 'Success! - '.$createResultText.'<br/>';
	}
	else
	{
		$resultText .= '<strong>Failed!</strong> - '.$createResultText.'<br/>';
		$success = false;
	}
}	

// if everything succeeded, write out "OK" so the calling routine knows the result
if ($success) 
{
	echo 'OK<br/>';  	
}
else
{
	echo 'FAIL<br/>';
}

echo $resultText;

?>